home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / GRAPH_FO / (GRAPH / GRAPH_SO / GRNODE.C < prev    next >
Text File  |  1991-06-13  |  3KB  |  151 lines

  1. /******************************************************************************
  2.     GrNode.c    
  3.         Graph methods in Object C.
  4.         This implements the GrNode class, base for GrVertex and GrEdge.
  5.         
  6.     SUPERCLASS = CObject
  7.     
  8.     Copyright ⌐ 1991 Maarten Meijer. All rights reserved.
  9.         CIS 100016,1764; FidoNet 2:512/114
  10. *******************************************************************************/
  11.  
  12.  
  13. #include "GrNode.h"
  14. #include <Global.h>
  15.  
  16. /* GrNode methods ****************************************************/
  17.  
  18. void
  19. GrNode::IGraphNode() {
  20.     hotRegion = NULL;
  21.     selected = false;
  22.     }
  23.  
  24. /* the copy method does not make new edges from a vertex or
  25.     copy the toVertex and fromVertex of an edge */
  26. CObject *
  27. GrNode::Copy() {
  28.     CObject *temp;
  29.     temp = inherited::Copy();
  30.     /* otherwise it is disposed !! */
  31.     ((GrNode *)temp)->hotRegion = NULL;
  32.     ((GrNode *)temp)->SetRegion();
  33.     return temp;
  34.     }
  35.  
  36. short
  37. GrNode::Track() {
  38.     Point    pt;
  39.     Boolean    track;
  40.  
  41.     InvertRgn(hotRegion);
  42.     while(Button()) {
  43.         GetMouse(&pt);
  44.         if(!(track = PtInRgn(pt, hotRegion)))
  45.             break;
  46.         }
  47.     InvertRgn(hotRegion);
  48.     if(track)
  49.         return 1;    /* make part code possible */
  50.     else
  51.         return 0;
  52.     }
  53.  
  54. /******************************************************************************
  55.     _Draw & Draw
  56.     
  57.         Draw the Node.
  58. *******************************************************************************/
  59. void
  60. GrNode::_Draw() {
  61.     }
  62.  
  63. void
  64. GrNode::Draw() {
  65.     }
  66.  
  67.  
  68. void
  69. GrNode::Select() {
  70.     selected = !false;
  71.     }
  72.  
  73. void
  74. GrNode::Deselect() {
  75.     selected = false;
  76.     }
  77.  
  78. void
  79. GrNode::ToggleNode(Boolean redraw) {
  80.     selected = !selected;
  81.     if(redraw)
  82.         Draw();
  83.     }
  84.  
  85. Boolean
  86. GrNode::Selected() {
  87.     return (selected);
  88.     }
  89.  
  90. /******************************************************************************
  91.     Setting and accessing the hot region of the node.
  92.     
  93.     The function _SetRegion should be changed to a method for GrList,
  94.     because this is accessing local variables from outside a class.
  95. *******************************************************************************/
  96. void
  97. _SetRegion(GrNode *this) {
  98.     this->SetRegion();
  99.     }
  100.  
  101. void
  102. GrNode::SetRegion() {
  103.     if(hotRegion != NULL)
  104.         DisposeRgn(hotRegion);
  105.     hotRegion = NewRgn();
  106.     }
  107.  
  108. Boolean
  109. GrNode::PtInNode(Point where) {
  110.     return PtInRgn(where, hotRegion);
  111.     }
  112.  
  113. Boolean
  114. GrNode::Incident(GrNode *which) {
  115.     return false;
  116.     }
  117.  
  118. /******************************************************************************
  119.     GetRect
  120.     
  121.         Get the spanning rect, needed for redrawing.
  122. *******************************************************************************/
  123. void
  124. GrNode::GetRect(Rect *rect) {
  125.     }
  126.  
  127. /******************************************************************************
  128.     NodeInRect
  129.     
  130.         Determine or the node is inside the rect and needs to be redrawn.
  131.         This is necessary for speed reasons. With larger graphs it pays
  132.         of to determine or redrawing is necessary and not to depend on
  133.         the clipregion only.
  134. *******************************************************************************/
  135. Boolean
  136. GrNode::NodeInRect(Rect *r) {
  137.     return    FALSE;
  138.     }
  139.  
  140. /******************************************************************************
  141.     Dispose
  142.     
  143.         Dont forget the hotRegion.
  144. *******************************************************************************/
  145. void
  146. GrNode::Dispose() {
  147.     if(hotRegion != NULL)
  148.         DisposeRgn(hotRegion);
  149.     inherited::Dispose();    /* CObject */
  150.     }
  151.